/// <reference path="./index.d.ts" />

namespace jsapp
{
    export class App {

        constructor() {

        }

        Init(): void {
            CS.TT.Log("hello world from js", CS.LogLevel.Normal);


            CS.TT.SetEvent_OnUpdate(this.OnUpdate);

            var names = CS.TT.RootPack.GetAllResourceName();
            for (var i = 0; i < names.Length; i++) {
                CS.TT.Log("res=" + names.get_Item(i));
            }

          
            //let font = CS.TTFont.FromAssetByName("hzk16");
            //CS.TT.Log("load hzk16.");

            for(var i=0;i<100;i++)
            { 
                CS.TT.Log("count=" + i);
                let  t = this.LoadTex("cat");
            }
            //let  ct = this.LoadTex("cat");
            //let  ct2 = this.LoadTex("cat");
        }
        timer: number = 0;
        count: number = 0;
        OnUpdate(delta: number) {

            this.timer += delta;
            if (this.timer > 1.0) {
                this.timer = 0;
                this.count++;
                CS.TT.Log("tick from js.");
            }

            //if (count > 5)
            //    throw "fucked.";

        }

        LoadTex(name:string):CS.TTImg
        { 
            CS.TT.Log("LoadTex 0:" + name);
            let img = CS.TTImg.FromAssetByName(name);
            CS.TT.Log("LoadTex 2 TTimg:" + img.Name);
            return img;
        }
    }
}